#Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=webencodings
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}"  "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.5.1
pkgrel=2
arch=('any')
pkgdesc="This is a Python implementation of the WHATWG Encoding standard. (mingw-w64)"
url="https://github.com/gsnedders/python-webencodings"
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2" "${MINGW_PACKAGE_PREFIX}-python3" "${MINGW_PACKAGE_PREFIX}-python3-setuptools" "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/gsnedders/python-webencodings/archive/v$pkgver.tar.gz")
sha256sums=('082367f568a7812aa5f6922ffe3d9d027cd83829dc32bcaac4c874eeed618000')

prepare() {  
  cd "${srcdir}"  
  for pver in {2,3}; do 
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "python-${_realname}-${pkgver}" "python${pver}-build-${CARCH}"
  done
}  

# Note that build() is sometimes skipped because it's done in 
# the packages setup.py install for simplicity if you can do so.
# but sometimes, you want to do a check before install which would
# also trigger the build.  
build() {  
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done  
}


check() {
  for pver in {2,3}; do
    cd "${srcdir}/python${pver}-build-${CARCH}/build/lib/webencodings/"
    ${MINGW_PREFIX}/bin/nosetests${pver} 
  done
}

package_python3-webencodings() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root=${pkgdir} --skip-build
}

package_python2-webencodings() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")

  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root=${pkgdir} --skip-build
}

package_mingw-w64-i686-python2-webencodings() {
  package_python2-webencodings
}

package_mingw-w64-i686-python3-webencodings() {
  package_python3-webencodings
}

package_mingw-w64-x86_64-python2-webencodings() {
  package_python2-webencodings
}

package_mingw-w64-x86_64-python3-webencodings() {
  package_python3-webencodings
}
